define(['jquery', './util/WebApi', 'leanModal', 'validate'], function($, WebApi){
	
	$(function(){
		
		$('#newOrder').on('submit', function(e){
			var form = e.target;
			var $form = $(form);
			
			var success = function() {
				$('#confirmSentModal').trigger('show');
			};
			
			var error = function() {
				$('#serverErrorModal').trigger('show');
			};
			
			if($form.valid()){
				WebApi.submitOrderForm({
					name : form.name.value,
					phone : form.phone.value,
					message : form.message.value,
					reason : form.reason.value
				}, success, error);
			}

			e.preventDefault();
			return false;
		});
	});

});